const Koa = require('koa');
const app = new Koa();
const browser = require('child_process')
const PORT = 3000
const logger = require('koa-logger')
const session = require('koa-session')

// 对 session 进行加密
app.keys = ['tao']

app.use(logger())
app.use(session(app))

app.use(ctx => {
    // ignore favicon
    if (ctx.path === '/') {
        let n = ctx.session.views || 0
        ctx.session.views = ++n
        ctx.body = n + ' views'
    } else if (ctx.path === '/hello') {
        ctx.body = 'hello'
    } else {
        ctx.body = '404'
    }
    
})

app.listen(PORT)
/* 
console.log('[demo] start-quick is starting at port ' + PORT) */
browser.exec('start http://127.0.0.1:' + PORT)